// 快排
function quickSort(arr) {
  if (arr.length < 2) return arr
  let middle = Math.floor(arr.length / 2)
  let middleNum = arr[middle]
  let left = []
  let right = []

  arr.forEach(item => {
    if (item > middleNum) {
      right.push(item)
    } else {
      left.push(item)
    }
  })
  return [...quickSort(left), middleNum, ...quickSort(right)];
}



console.log(quickSort([3, 6, 2, 4, 1]));